//页面加载完成执行此程序
$(function(){
    $("#submit").attr("disabled","disabled");
});
//赋值方法
$(".el-upload__input").change(function(){
    var see =  $(".el-upload__input").val();
    $("#picture").val(see);
});
//提交按钮状态设置
function enableSubmit(bool){
    if(bool) {
        $("#submit").removeAttr("disabled");
    } else $("#submit").attr("disabled","disabled");
}

//验证多少项，多少个false
var flags = [false,false,false,false,false,false,false,false,false,false,false,false];
//flags全为true时提交按钮解除禁用
function v_submitbutton(){
    for(f in flags) if(!flags[f]) {
        enableSubmit(false);
        return;
    }
    enableSubmit(true);
}
//市场价格/供货价格正则
var RegPrice = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
/*//库存正则
var Regstock = /^[0-9]{1,5}$/;*/
//图片验证
var RegPicture = /^\S+\.(jpg|png|)$/;
/*//质保时间
var RegQuality =  /^[0-9]{1,2}$/;*/

//验证商品名称
function v_shopsname(){
    var shopname = $("#user-name2").val();
    if(shopname.trim() =="") { flags[0]=false;enableSubmit(false);
        $("#tab1").html("请输入商品名称");$("#img-icon1-2").css("display","block");$("#img-icon1-1").css("display","none");$("#tab1").css("display","block");$("#user-name2").css("border","solid 1px red");}
    else{flags[0] = true;
        $("#user-name2").css("border","solid 1px #2dc12d","");$("#img-icon1-1").css("display","block");$("#tab1").css("display","none");$("#img-icon1-2").css("display","none");}
    v_submitbutton();
}
/*//验证文件
function v_picture(){
    var picture = $("#picture").val();
    if(!RegPicture.test(picture)) { flags[1]=false;enableSubmit(false);
        $("#tab12").html("请选择上传文件");$("#img-icon12-2").css("display","block");$("#img-icon12-1").css("display","none");$("#tab12").css("display","block");$("#picture").css("border","solid 1px red");}
    else{flags[1] = true;
        $("#picture").css("border","solid 1px #2dc12d","");$("#img-icon12-1").css("display","block");$("#tab12").css("display","none");$("#img-icon12-2").css("display","none");}
    v_submitbutton();
}*/
//验证商品类型
function v_type(){
    var length = $(".el-cascader__label").find("span").length
    if(length ==0){ flags[1]=false;enableSubmit(false);
        $("#tab2").html("请选择商品类型");$(".el-cascader__label").css("border","solid 1px red");$("#tab2").css("display","block");$("#img-icon2-2").css("display","block");$("#img-icon2-1").css("display","none");}
    else{flags[1] = true;
        $(".el-cascader__label").css("border","solid 1px #2dc12d","");$("#tab2").css("display","none");$("#img-icon2-1").css("display","block");$("#img-icon2-2").css("display","none");}
    v_submitbutton();
}
//验证品牌名称
function v_brandname(){
    v_type();
    var brandname = $("#brand").val();
    if(brandname.trim() =="") { flags[2]=false;enableSubmit(false);
        $("#tab3").html("请输入品牌名称");$("#img-icon3-2").css("display","block");$("#tab3").css("display","block");$("#img-icon3-1").css("display","none");$("#brand").css("border","solid 1px red");}
        else{flags[2] = true;
        $("#brand").css("border","solid 1px #2dc12d","");$("#img-icon3-1").css("display","block");$("#tab3").css("display","none");$("#img-icon3-2").css("display","none");}
    v_submitbutton();
}
//验证商品型号
function v_model(){
    var modelname = $("#model").val();
    if(modelname.trim() =="") { flags[3]=false;enableSubmit(false);
        $("#tab4").html("请输入商品型号");$("#img-icon4-2").css("display","block");$("#tab4").css("display","block");$("#img-icon4-1").css("display","none");$("#model").css("border","solid 1px red");}
    else{flags[3] = true;
        $("#model").css("border","solid 1px #2dc12d","");$("#img-icon4-1").css("display","block");$("#tab4").css("display","none");$("#img-icon4-2").css("display","none");}
    v_submitbutton();
}
//验证商品代码
function v_Num(){
    var Numname = $("#Num").val();
    if(Numname.trim() =="") { flags[4]=false;enableSubmit(false);
        $("#tab5").html("请输入商品代码");$("#img-icon5-2").css("display","block");$("#tab5").css("display","block");$("#img-icon5-1").css("display","none");$("#Num").css("border","solid 1px red");}
    else{flags[4] = true;
        $("#Num").css("border","solid 1px #2dc12d","");$("#img-icon5-1").css("display","block");$("#tab5").css("display","none");$("#img-icon5-2").css("display","none");}
    v_submitbutton();
}
//验证质保时间
function v_quality(){
    var quality = $("#quality").val();
    if(quality.trim()=="") { flags[5]=false;enableSubmit(false);
        $("#tab6").html("质保时间不能为空！");$("#img-icon6-2").css("display","block");$("#tab6").css("display","block");$("#img-icon6-1").css("display","none");$("#quality").css("border","solid 1px red");}
    else{flags[5] = true;
        $("#quality").css("border","solid 1px #2dc12d","");$("#img-icon6-1").css("display","block");$("#tab6").css("display","none");$("#img-icon6-2").css("display","none");}
    v_submitbutton();
}
//验证制造商
function v_manufacturer(){
    var manufacturer = $("#manufacturer").val();
    if(manufacturer.trim() =="") { flags[6]=false;enableSubmit(false);
        $("#tab7").html("请输入制造商");$("#img-icon7-2").css("display","block");$("#tab7").css("display","block");$("#img-icon7-1").css("display","none");$("#manufacturer").css("border","solid 1px red");}
    else{flags[6] = true;
        $("#manufacturer").css("border","solid 1px #2dc12d","");$("#img-icon7-1").css("display","block");$("#tab7").css("display","none");$("#img-icon7-2").css("display","none");}
    v_submitbutton();
}
//验证市场价格
function v_commodityMakPrc(){
    var price = $("#commodityMakPrc").val();
    if(!RegPrice.test(price)) { flags[7]=false;enableSubmit(false);
        $("#tab8").html("请输入市场价格");$("#img-icon8-2").css("display","block");$("#tab8").css("display","block");$("#img-icon8-1").css("display","none");$("#commodityMakPrc").css("border","solid 1px red");}
    else{flags[7] = true;
        $("#commodityMakPrc").css("border","solid 1px #2dc12d","");$("#img-icon8-1").css("display","block");$("#tab8").css("display","none");$("#img-icon8-2").css("display","none");}
    v_submitbutton();
}
//验证供货价格
function v_commodityTrcPrc(){
    var price = $("#commodityMakPrc").val();
    var commodityTrcPrc = $("#commodityTrcPrc").val();
    if(!RegPrice.test(commodityTrcPrc)||Number(commodityTrcPrc)>=Number(price)) {
        flags[8]=false;enableSubmit(false);
        $("#tab9").html("请输入供货价格，且供货价格应低于市场价格");$("#img-icon9-2").css("display","block");$("#tab9").css("display","block");$("#img-icon9-1").css("display","none");$("#commodityTrcPrc").css("border","solid 1px red");}
    else{
        flags[8] = true;
        $("#commodityTrcPrc").css("border","solid 1px #2dc12d","");$("#img-icon9-1").css("display","block");$("#tab9").css("display","none");$("#img-icon9-2").css("display","none");}
    v_submitbutton();
}
//验证库存
function v_stock(){
    var stock = $("#stock").val();
    if(stock.trim()=="") { flags[9]=false;enableSubmit(false);
        $("#tab10").html("请输入库存信息");$("#img-icon10-2").css("display","block");$("#tab10").css("display","block");$("#img-icon10-1").css("display","none");$("#stock").css("border","solid 1px red");}
    else{flags[9] = true;
        $("#stock").css("border","solid 1px #2dc12d","");$("#img-icon10-1").css("display","block");$("#tab10").css("display","none");$("#img-icon10-2").css("display","none");}
    v_submitbutton();
}
//验证产品描述
function v_rests(){
    var rests = $("#rests").val();
    if(rests.trim() =="") { flags[10]=false;enableSubmit(false);
        $("#tab11").html("请简单描述");$("#img-icon11-2").css("display","block");$("#tab11").css("display","block");$("#img-icon11-1").css("display","none");$("#rests").css("border","solid 1px red");}
    else{flags[10] = true;
        $("#rests").css("border","solid 1px #2dc12d","");$("#img-icon11-1").css("display","block");$("#tab11").css("display","none");$("#img-icon11-2").css("display","none");}
    v_submitbutton();
}
//验证商品单位
function v_unit(){
    var res = $("#selected").val();
    if(res.trim() =="") { flags[11]=false;enableSubmit(false);
        $("#tab13").html("请简单描述");$("#img-icon13-2").css("display","block");$("#tab13").css("display","block");$("#img-icon13-1").css("display","none");$("#selected").css("border","solid 1px red");}
    else{flags[11] = true;
        $("#selected").css("border","solid 1px #2dc12d","");$("#img-icon13-1").css("display","block");$("#tab13").css("display","none");$("#img-icon13-2").css("display","none");}
    v_submitbutton();
}
function adaptValue(){
    return true;
}
